﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Xml.Serialization;

namespace Samples.WebService.Models
{
    public class Product
    {
        public string Uri { get; set; }
        public int Id { get; set; }
        public string Name { get; set; }
        public int CategoryId { get; set; }
        public Decimal? UnitPrice { get; set; }
        public int UnitsInStock { get; set; }

        public Category Category { get; set; }

        private static ProductCollection _allProducts;
        public static ProductCollection AllProducts
        {
            get
            {
                if (_allProducts == null)
                {
                    _allProducts = new ProductCollection
                                      {
                                          new Product
                                              {
                                                  Category = new Category {CategoryId = 1, Name = "Soda"},
                                                  CategoryId = 1,
                                                  Name = "Coke",
                                                  Id = 1,
                                                  UnitPrice = 1.25M,
                                                  UnitsInStock = 101
                                              },
                                          new Product
                                              {
                                                  Category = new Category {CategoryId = 2, Name = "Meat"},
                                                  CategoryId = 2,
                                                  Name = "Flank Steak",
                                                  Id = 2,
                                                  UnitPrice = 35.45M,
                                                  UnitsInStock = 2
                                              },
                                          new Product
                                              {
                                                  Category = new Category {CategoryId = 3, Name = "Cereal"},
                                                  CategoryId = 3,
                                                  Name = "Cheerios",
                                                  Id = 3,
                                                  UnitPrice = 3.45M,
                                                  UnitsInStock = 88
                                              }
                                      };

                    foreach (var product in _allProducts)
                    {
                        Category.AllCategories.Add(product.Category);
                    }
                }

                return _allProducts;
            }
        }
    }
}